import {Component} from 'react';
import {buildPermission} from '~/component/SearchForm/helps';

import AddModalForm from '../ModalSearchForm';

class AddComparsionView extends Component {
    // 点击OK
    onOk = () => {
        const {form} = this.formRef.props;
        form.validateFields((error, fieldsValue) => {
            if (error) {
                return;
            }
            const permList = buildPermission(fieldsValue);
            this.props.onOk({
                permissions: permList
            });
        });
    };

    saveFormRef = formRef => {
        this.formRef = formRef;
    };

    render() {
        const {isVisiable, data, onCancel, statisticsId} = this.props;
        return (
            <AddModalForm
                isVisiable={isVisiable}
                data={data}
                onOk={this.onOk}
                onCancel={onCancel}
                wrappedComponentRef={this.saveFormRef}
                statisticsId={statisticsId}
            />
        );
    }
}

export default AddComparsionView;
